package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.dto.FreezeDto;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wjs
 * @version 1.0
 * @date 2022/1/3 0003 下午 3:00
 */

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManagerService managerService;

    /**
     * 查询用户列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看用户详情
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId) {
        UserInfo userInfo = managerService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 查询指定用户发布的所有视频列表
     * @param page
     * @param pagesize
     * @param uid
     * @return
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid ) {
        PageResult result = managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询指定用户发布的所有动态列表
     * @param page
     * @param pagesize
     * @param uid
     * @param state
     * @return
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state) {
        PageResult result = managerService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    /**
     * 动态详情
     * @param id
     * @return
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity findMovementById(@PathVariable("id") String id){
        return managerService.findMovementById(id);
    }

    /**
     * 评论列表翻页
     * @param page
     * @param pagesize
     * @param messageID
     * @return
     */
    @GetMapping("/messages/comments")
    public ResponseEntity findCommentsByMessageId(@RequestParam(defaultValue = "1") Integer page,
                                                  @RequestParam(defaultValue = "10") Integer pagesize,
                                                  String messageID){
        return managerService.findCommentsByMessageId(page,pagesize,messageID);
    }

    /**
     * 用户冻结
     * @param dto
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody FreezeDto dto) {
        Map map =  managerService.userFreeze(dto);
        return ResponseEntity.ok(map);
    }

    /**
     * 用户解冻
     * @param dto
     * @return
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  FreezeDto dto) {
        Map map =  managerService.userUnfreeze(dto);
        return ResponseEntity.ok(map);
    }


}
